package com.hitsoysauce.date20121229.launcher;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * <p>日期构造函数推荐使用的是两种 new Date()、new Date(long milliseconds)，别的都已经过时</p>
 * <p>Date类现在只用来表示时间点，不在有其它用途，它绝大多数方法都已废弃。</p>
 * <p>现在用来表示日历信息的类是GregorianCalendar，表示公历，它扩展自Calendar抽象类。如需要实现其它的日历，如中国的农历也可扩展Calendar类。</p>
 * 
 * 
 * @author liupj
 *
 */
public class TestDate {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		
		
		//空构造函数，表示默认为当前时间
		Date now = new Date();
		
		//已毫秒偏移量初始化Date
		Date now2 = new Date(System.currentTimeMillis());
		
		boolean result1 = now.equals(now2);
		
		boolean result2 = now.compareTo(now2) == 0;
		
		Calendar nowCalendar = Calendar.getInstance();
		nowCalendar.setTime(now);
		
		System.out.println("now = " + simpleDateFormat.format(nowCalendar.getTime()));
		System.out.println("now2 = " + simpleDateFormat.format(now2));
		
		System.out.println("result1 = " + result1);
		System.out.println("result2 = " + result2);
		
		System.out.println("Year = " + nowCalendar.get(Calendar.YEAR));
		System.out.println("Month = " + (nowCalendar.get(Calendar.MONTH) + 1));
		System.out.println("Day = " + nowCalendar.get(Calendar.DAY_OF_MONTH));
		System.out.println("Hour = " + nowCalendar.get(Calendar.HOUR_OF_DAY));
		System.out.println("Minute = " + nowCalendar.get(Calendar.MINUTE));
		System.out.println("Second = " + nowCalendar.get(Calendar.SECOND));
		
		System.out.println("DayOfWeek" + nowCalendar.get(Calendar.DAY_OF_WEEK)); //sunday ~ Saturday : 1 ~ 7
	}

}



